# print(1)
# print(2)
# print(3)
# print(4)

# def pFunc():
#     print(1)
#     print(2)
#     print(3)
#     print(4)
#
#
# pFunc()

# def test():
#     print(2**1)
#     print(2**2)
#     print(2**3)

# def test2(num):
#     print(num**1)
#     print(num**2)
#     print(num**3)
#
# test()
# test2(3)

# def mySum(num1,num2,num3):
#     print(num1+num2+num3)

# def mySum(*t):  #加 *不用加括号算是元组  *不定长参数
#     # print(t,type(t))
#     result=0
#     for v in t:
#         result+=v
#     return  result
#
# print(mySum(1,2,3,4,5,6,7))

# def mySum(**kwargs): #加两个**默认当做字典
#     print(kwargs,type(kwargs))
#
# mySum(name="sz",age=12)

# def mySum(a,b,c,d):
#     print(a+b+c+d)
#
# def test(*args):
#     print(args)
#
#     #拆包
#     print(*args)
#     # mySum(args[0],args[1],args[2],args[3])
#
#     # mySum(args[0])
#
#     mySum(*args)
#
# test(1,2,3,4)


# def mySum(a,b):
#     print(a)
#     print(b)
#
# def test(**kwargs):
#     print(kwargs)
#
#     # print(**kwargs)
#     # mySum(**kwargs)
#     mySum(a=1,b=2)
# #参数需要一一对应，拆包也是
# test(a=1,b=2)

# result=sorted([1,2,4,5,3,6],reverse=True)
# print(result)

# def hit(somebody="dd"):
#     print("wxd",somebody)
# hit("zs")

# def change(num):
#     print(id(num))
#     # print(num)
#     # num=666
#     num.append(666)
#     print(id(num))
#
#
# b=[1,2,3]
# print(id(b))
# change(b)
# print(b)

# def mySum(a,b):
#     # print(a+b)
#     return a+b
#     # print("xxx")
#
# print(mySum(6,7))

# def caculate(a,b):
#     # print(a+b)
#     h=a+b
#     c=a-b
#     return (h,c)
#     # print("xxx")
#
# # print(caculate(6,7))
# h,c=caculate(7,6)
# print(h)
# print(c)



# def caculate(a,b=1):
#     # print(a+b)
#
#     """
#     计算两个数据的和，及差
#     :param a: 数值1，数值类型 不可选 没有默认值
#     :param b: 数值二，数值类型 可选 默认值：1
#     :return:  返回的是计算结果，元组：（和，差）
#     """
#
#     h=a+b
#     c=a-b
#     return (h,c)
#     # print("xxx")
#
# # h,c=caculate(7,6)
# # print(h)
# # print(c)

# help(caculate)

#偏函数
# def test(a,b,c,d=1):
#     print(a+b+c+d)

# test(1,2,3)

# def test2(a,b,c=1,d=2):
#     test(a,b,c,d)

# test2(1,2)

# import functools
#
# newFunc=functools.partial(test,c=5)
# # print(newFunc,type(newFunc))
#
# newFunc(1,2)

# numStr="100010"
# result=int(numStr,base=2)
# print(result)
#
# #在往后的一段时间内，我都要把一个二进制的字符串，转换成对应的十进制数据
# import functools
# int2=functools.partial(int,base=2)
# print(int2(numStr))

#a,b 形参，变量
#传递数据 就是指给变量赋值
#函数本身，也可以作为数据，传递给另外一个变量
# def test(a,b):
#     print(a+b)
#
# print(test)
# print(id(test))
#
# test2=test
# test2(1,2)

# l=[{"name":"bz1","age":18},{"name":"az2","age":19},{"name":"sz3","age":18.5}]
#
# def getKey(x):
#     return  x["name"]
#
#
# result=sorted(l,key=getKey)
# print(result)

# def caculate(num1,num2,caculateFunc):
#     print(caculateFunc(num1,num2))
#
# def sum(a,b):
#     return a+b
#
# def muns(a,b):
#     return a-b
#
# caculate(6,2,muns)

# def getFunc(flag):
#     #定义几个函数
#     def sum(a,b,c):
#         return a+b+c
#     def muns(a,b,c):
#         return a-b-c
#
#     if flag=="+":
#         return sum
#
#     elif flag=="-":
#         return muns

# result=getFunc("-")
# # print(result,type(result))
# res=result(1,2,3)
# print(res)

#匿名函数

# result=(lambda x,y:x+y)(1,2)
#
# print(result)
#
# newFunc=lambda x,y:x+y
# print(newFunc(4,5),type(newFunc))


# l=[{"name":"bz1","age":18},{"name":"az2","age":19},{"name":"sz3","age":18.5}]
#
# # def getKey(x):
# #     return  x["name"]
#
# # result=sorted(l,key=getKey)
# result=sorted(l,key=lambda x:x["age"])
# print(result)

# def test():
#     a=10
#     def test2():
#         print(a)
#
#     return test2
#
# newFunc=test()
# newFunc()

# def line_config(content,length):
#     def line():
#         print("-"*(length//2)+content+"-"*(length//2))
#     return line
#
# line1=line_config("***",20)
#
# line1()
#
# # line_config("***",20)
#
# line2=line_config("dwed",80)
# line2()

# def test():
#     num=10
#     def test2():
#         nonlocal num
#         num=666
#         # print(a)
#         print(num)
#     print(num)
#     test2()
#     print(num)
#
#     return  test2
#
# result=test()

# result()

# def test():
#     a=1
#     def test2():
#         print(a)
#     a=2
#
#     return test2
#
# newFunc=test()
# newFunc()


#函数，什么时候，才会确定，内部，变量标识，对应的值
#当函数被调用的时候，才会真正的确定，对应的值，到底是什么，之前，都是以普通的变量标识
# def tedt():
#
#     print(b)
#
# print("XXX")
#
# # test()

# def test():
#     funcs=[]
#     for i in range(1,4):
#         def test2():
#             print(i)
#         funcs.append(test2)
#     return funcs
#
#
# newFunc=test()
# print(newFunc)
#
# newFunc[0]()
# newFunc[1]()
# newFunc[2]()


# def test():
#     funcs=[]
#     for i in range(1,4):
#         def test2(num):
#             def inner():
#                 print(num)
#             return  inner
#         funcs.append(test2(i))
#     return funcs
#
#
# newFunc=test()
# print(newFunc)
#
# newFunc[0]()
# newFunc[1]()
# newFunc[2]()

#newFunc 里面是函数inner

# #装饰器
# def checkLogin(func):
#     def inner():
#         print("登录验证...")
#         func()
#     return inner
#
# # def checkLogin2():
# #     print("登录验证...")
# #     ftp()
#
# @checkLogin
# def fss():
#     # checkLogin()
#     print("发说说")
#
# # fss=checkLogin(fss)
# # print(fss)
#
# # fss=def inner():
# #         print("登录验证...")
# #         fss()
#
# #语法糖 写法
# @checkLogin
# def ftp():
#     # checkLogin()
#     print("发图片")
#
# # ftp=checkLogin(ftp)
#
#
# btIndex=2
# if btIndex==1:
#     # print("登录验证...")
#     fss()
#     # checkLogin(fss)
# else:
#     # print("登录验证...")
#     ftp()
#     # checkLogin(ftp)
#
# #必须有个前提,用户必须登录
# #登录验证
#
# #1.直接在业务逻辑代码里面去修改，添加一个验证操作
# # 因为业务逻辑代码非常多，所以，就造成了每一份，逻辑代码，在调用，具体的功能函数之前
# # 都需要，去做一个登录验证，代码冗余度比较大，代码的复用性比较差，代码的维护性比较差
# #2.直接在功能函数里面，去修改，方便代码的重用


#给发说说函数增加一些额外的功能
#1.函数名字不能发 生改变
#2.函数体内部代码不能发生改变

# def check(func):
#     # print("XXX")
#     def inner():
#         print("登录验证...")
#         func()
#     return inner
#
# #装饰器，执行时间，立即执行
# @check  #等同于fss=check(fss)
# def fss():
#     print("发说说")
#
# # fss=check(fss)
#
# # check(fss)
# fss()


# def ZSQ_line(func):
#     def inner():
#         print("_____")
#         func()
#     return inner
#
# def ZSQ_star(func):
#     def inner():
#         print("*"*10)
#         func()
#     return inner
#
# #装饰器叠加，从上到下装饰，从下到上执行
#
# @ZSQ_line
# #==print_content==ZSQ_line(print_content)
# @ZSQ_star  #紧跟下面函数
# #==print_content=ZSQ_star(print_content)
#
# #print("_____")
# # print("*"*10)
# # print("XXXXXX")
# def print_content():
#     print("XXXXXX")
#
# print_content()

# def ZSQ(func):
#     def inner(*args,**kwargs):
#         print("_"*30)
#         # print(args,kwargs)
#         res=func(*args,**kwargs)  #指向的就是pnum( )函数
#         return  res
#     return inner #pnum() 指向的是inner()
#
# @ZSQ  # pnum=ZSQ(pnum)
# def pnum(num1,num2,num3):
#     print(num1,num2,num3)
#     return num1+num2+num3
#
# @ZSQ
# def pnum2(num):
#     print(num)
#
# res1=pnum(123,345,num3=666)
# res2=pnum2(2342)
#
# print(res1,res2)


# def GetZSQ(char):
#     def ZSQ(func):
#         def inner():
#             print(char * 30)
#             func()  # 等同于f1()
#
#         return inner
#     return ZSQ
 # def ZSQ(func,char):
#     def inner():
#         print('_'*30)
#         func()  #等同于f1()
#     return inner

# def ZSQE(func):
#     def inner():
#         print('='*30)
#         func()  #等同于f1()
#     return inner
#
# def ZSQS(func):
#     def inner():
#         print('*'*30)
#         func()  #等同于f1()
#     return inner

# @GetZSQ("*")  #f1=ZSQ(f1 )
# def f1():
#     print("666")
#
# f1()
#
# #带有参数的装饰器，通过@装饰器（参数）的方式，调用这个函数，并传递参数；并把返回值，再次当做装饰器进行使用
# #先计算@后面的内容，把这个内容当做是装饰器

#生成器
#是一个特殊的迭代器（迭代器的抽象层级更高）

# # l=[i for i in range(1,10) if i % 2==0]
# l=(i for i in range(1,10) if i % 2==0)
# print(next(l))
# # print(next(l))
# # print(next(l))
# print(l.__next__())
#
# for i in l:
#     print(i)

#生成器的创建方式2
# yield,可以去阻断当前的函数执行，然后，当使用next()函数，或者，__next__(),
#都会让函数继续执行，然后，当执行到下一个yield语句的时候，又会被暂停 会返回yield语句后的数字


# def test():
#     print("xxx")
#     yield 1
#     print("a")
#
#     yield 2
#     print("b")
#
#     yield 3
#     print("c")
#
#     yield 4
#     print("d")
#
#     yield 5
#     print("e")
#
#     # yield 6
#
# g=test()
# print(g)
#
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# print(next(g))
# # print(next(g))

# def test():
#     for i in range(1,9):
#         yield i
#
# g=test()
# print(g)
#
# print(next(g))
# print(next(g))
# print(next(g))


#send() 相比.__next__() 可以额外的给yield语句 传值
#send方法有一个参数，指定的是上一次被挂起的yield语句的返回值
# def test():
#     res1=yield 1  # ”00“
#     print(res1)
#     res2=yield 2
#     print(res2)
#
# g=test()
# # for i in g:
# #     print(i)
# # print(g.__next__())
# # # print(g.__next__())
# print(g.send(None))#第一次调用得传None
# print(g.send(666))


# def test():
#     yield  1
#     print("a")
#
#     yield 2
#     print("b")
#
#     yield 3
#     print("c")
#
#     return 10
#
# g=test()
#
# print(g.__next__())
# print(g.__next__())
# # print(g.__next__())
# # print(g.__next__())
#
# # g.close()#关闭
# # print(g.__next__())



# def test():
#     yield  1
#     print("a")
#
#     # return 10
#
#     yield 2
#     print("b")
#
#     yield 3
#     print("c")
#
#     # return 10
#
# # g=test()
# #
# # print(g.__next__())
# # print(g.__next__())
# # print(g.__next__())
# # print(g.__next__())#
#
# # g.close()#关闭
# # print(g.__next__())
#
# g=test()
# #生成器只会被遍历一次
# #要运行就在创造一个
# for i in g:
#     print(i)
#
# t=test()
# print("-"*30)
# for i in t:
#     print(i)


#递归函数
#求阶乘


# def Fun(num):
#     if(num==0 or num==1):
#         return 1
#
#     else:
#         return num*Fun(num-1)
#
# print(Fun(4))

# b=10
# def test():
#     a=1
#     print(b)
#
# print(b)
# test()

# import os
# os.remove()
#
# xxx.remove()
#
# __name__

# if True:
#     a=10
#
# print(a)

# a=999
# def test():
#     a=1
#     a=2
#     print(a)
#     def test2():
#         # nonlocal  a
#         a=10
#         print(a)
#     test2()
#     print(a)
#
# test()

# print(a)

# a=999
# b=10
# def test():
#     global a
#     a=6
#     print(a)
#     # def test2():
#     #     nonlocal  a
#     #     a=77
#     b=10
#     c=0
#     print(locals())
#     print(globals())
# # print(a)
# test()
# # print(a)
#
#
# print(b)


g_a=1
g_b=10
def test():
    print(g_a)
    print(g_b)
test()



# test()

